-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(withTableSettings): isSelected -> selected, isRequired -> required #1478
Conversation
Playwright Test Component is ready. |
Preview is ready. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It breaks current behaviour
src/components/Table/README.md
Outdated
@@ -263,7 +263,7 @@ const MyTable1 = withTableSettings({sortable: false})(Table); | |||
```ts | |||
type TableSettingsData = Array<{ | |||
id: string; | |||
isSelected?: boolean; | |||
selected?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? It's a breaking change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, need to separate TableColumnSetupItem
from TableSetting
and return backward compatibility for TableColumnSetupItem
only
@@ -23,26 +23,26 @@ import './withTableSettings.scss'; | |||
|
|||
export type TableSetting = { | |||
id: string; | |||
isSelected?: boolean; | |||
selected?: boolean; | |||
}; | |||
|
|||
export type TableSettingsData = TableSetting[]; | |||
|
|||
export type TableColumnSetupItem = TableSetting & { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export type TableColumnSetupItem = TableSetting & { | |
export type TableColumnSetupItem = { |
required?: boolean; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
required?: boolean; | |
}; | |
selected?: boolean; | |
required?: boolean; | |
}; |
@@ -23,26 +23,26 @@ import './withTableSettings.scss'; | |||
|
|||
export type TableSetting = { | |||
id: string; | |||
isSelected?: boolean; | |||
selected?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
selected?: boolean; | |
isSelected?: boolean; |
6dce2a5
to
645df56
Compare
The problem is real I rewrote TableColumnSetup but I did not think that it was public component. Interfaces So, the best solution now to save backward compatibility in my opinion
What to do with new created TableColumnSetup component I do not know - probably delete it in future, but now save it for backward compatibility. |
@amje @korvin89 @Raubzeug @ValeraS I begin rewrite new
The best way to save backward compatibility in my opinion will be create In this case we 100% sure that new component will not be broken, users that use And after that we will think what to do with |
@@ -18,7 +18,7 @@ import type { | |||
import type {ListItemViewProps} from '../../../../useList'; | |||
import {ListContainerView, ListItemView} from '../../../../useList'; | |||
import {block} from '../../../../utils/cn'; | |||
import type {TableColumnSetupItem, TableSetting} from '../withTableSettings'; | |||
import type {TableSetting} from '../withTableSettings'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a circular dependency here, let's avoid such a case.
@@ -0,0 +1 @@ | |||
export * from './TableColumnSetup'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2b05fc1
to
2c4bb9a
Compare
@@ -288,7 +288,7 @@ describe('withTableSettings', () => { | |||
|
|||
await userEvent.click(screen.getByRole('button', {name: 'Table settings'})); | |||
await userEvent.click(await screen.findByRole('button', {name: 'description'})); | |||
await userEvent.click(screen.getByRole('button', {name: 'Apply'})); | |||
await userEvent.click(screen.getByRole('button', {name: 'button_apply'})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have no idea why it is broken now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because you test component const TableWithSettings = withTableSettings<SomeItem>(Table);
. And keysets are taken from https://github.com/gravity-ui/uikit/tree/839d503f378e23eef87887866d20973bcd174fb4/src/components/Table/hoc/withTableSettings/i18n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it be fixed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In separate PR, I do not know what happened with this place
let lastStickyLeftIdx = 0; | ||
for (; lastStickyLeftIdx !== visibleFlattenIds.length; lastStickyLeftIdx++) { | ||
const visibleFlattenId = visibleFlattenIds[lastStickyLeftIdx]; | ||
const item = items.find((item) => item.id === visibleFlattenId) as Item | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@IsaevAlexandr ListItemType
generic works bad.
Do not know why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/components/Table/hoc/withTableSettings/TableColumnSetup/TableColumnSetup.tsx
Outdated
Show resolved
Hide resolved
startSlot: tableColumnItem.isRequired ? <Icon data={Lock} /> : undefined, | ||
hasSelectionIcon, | ||
selected: hasSelectionIcon ? tableColumnItem.isSelected : undefined, | ||
}; | ||
}); | ||
}; | ||
|
||
const prepareStikyState = (items: ListItemType<Item>[], visibleFlattenIds: string[]) => { | ||
let lastStickyLeftIdx = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left
and right
names are obsolete in our code base, please use start
and end
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const stickyLeftItemIdList: string[] = []; | ||
for (let i = 0; i < lastStickyLeftIdx; i++) { | ||
const visibleFlattenId = visibleFlattenIds[i]; | ||
stickyLeftItemIdList.push(visibleFlattenId); | ||
} | ||
|
||
const sortableItemIdList: string[] = []; | ||
for (let i = lastStickyLeftIdx; i < firstStickyRightIdx; i++) { | ||
const visibleFlattenId = visibleFlattenIds[i]; | ||
sortableItemIdList.push(visibleFlattenId); | ||
} | ||
|
||
const stickyRightItemIdList: string[] = []; | ||
for (let i = firstStickyRightIdx; i < visibleFlattenIds.length; i++) { | ||
const visibleFlattenId = visibleFlattenIds[i]; | ||
stickyRightItemIdList.push(visibleFlattenId); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const stickyLeftItemIdList: string[] = []; | |
for (let i = 0; i < lastStickyLeftIdx; i++) { | |
const visibleFlattenId = visibleFlattenIds[i]; | |
stickyLeftItemIdList.push(visibleFlattenId); | |
} | |
const sortableItemIdList: string[] = []; | |
for (let i = lastStickyLeftIdx; i < firstStickyRightIdx; i++) { | |
const visibleFlattenId = visibleFlattenIds[i]; | |
sortableItemIdList.push(visibleFlattenId); | |
} | |
const stickyRightItemIdList: string[] = []; | |
for (let i = firstStickyRightIdx; i < visibleFlattenIds.length; i++) { | |
const visibleFlattenId = visibleFlattenIds[i]; | |
stickyRightItemIdList.push(visibleFlattenId); | |
} | |
const stickyLeftItemIdList = visibleFlattenIds.slice(0, lastStickyLeftIdx); | |
const sortableItemIdList = visibleFlattenIds.slice(lastStickyLeftIdx, firstStickyRightIdx); | |
const stickyRightItemIdList = visibleFlattenIds.slice(firstStickyRightIdx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const items = propsItems.map(({id, title, required, selected}) => ({ | ||
id, | ||
title, | ||
isRequired: required, | ||
isSelected: selected, | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const items = propsItems.map(({id, title, required, selected}) => ({ | |
id, | |
title, | |
isRequired: required, | |
isSelected: selected, | |
})); | |
const items = propsItems.map(({id, title, required, selected}) => ({ | |
id, | |
title, | |
isRequired: required, | |
isSelected: selected, | |
sticky: required ? "start" : undefiend | |
})); |
or add a sticky
field to TableColumnSetupItem
, otherwise the behavior of the component will be different from the previous one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
de23fe0
to
839d503
Compare
@@ -302,7 +365,7 @@ export const TableColumnSetup = (props: TableColumnSetupProps) => { | |||
|
|||
return ( | |||
<TreeSelect | |||
className={tableColumnSetupCn} | |||
className={b(null, className)} | |||
mapItemDataToProps={identity} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or better instead of prepareDndItems
and dndItems
use mapItemToProps
and items
mapItemDataToProps={identity} | |
mapItemDataToProps={mapItemToProps} | |
items={items} |
where
function mapItemToProps(item: TableColumnSetupItem): ListItemCommonProps {
return {
id: item.id,
title: item.title,
startSlot: item.isRequired ? <Icon data={Lock} /> : undefined,
hasSelectionIcon: !item.isRequired,
selected: !item.isRequired ? tableColumnItem.isSelected : undefined,
};
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think main reason is here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isRequired?: boolean; | ||
sticky?: TableColumnConfig<unknown>['sticky']; | ||
}; | ||
|
||
type Item = TableColumnSetupItem & |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is {id, isDragDisabled}
needed? id
is present in TableSetting
and isDragDisabled
is not used.
@@ -288,7 +288,7 @@ describe('withTableSettings', () => { | |||
|
|||
await userEvent.click(screen.getByRole('button', {name: 'Table settings'})); | |||
await userEvent.click(await screen.findByRole('button', {name: 'description'})); | |||
await userEvent.click(screen.getByRole('button', {name: 'Apply'})); | |||
await userEvent.click(screen.getByRole('button', {name: 'button_apply'})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because you test component const TableWithSettings = withTableSettings<SomeItem>(Table);
. And keysets are taken from https://github.com/gravity-ui/uikit/tree/839d503f378e23eef87887866d20973bcd174fb4/src/components/Table/hoc/withTableSettings/i18n
src/components/Table/hoc/withTableSettings/TableColumnSetup/TableColumnSetup.tsx
Outdated
Show resolved
Hide resolved
src/components/Table/hoc/withTableSettings/TableColumnSetup/TableColumnSetup.tsx
Show resolved
Hide resolved
@@ -288,7 +288,7 @@ describe('withTableSettings', () => { | |||
|
|||
await userEvent.click(screen.getByRole('button', {name: 'Table settings'})); | |||
await userEvent.click(await screen.findByRole('button', {name: 'description'})); | |||
await userEvent.click(screen.getByRole('button', {name: 'Apply'})); | |||
await userEvent.click(screen.getByRole('button', {name: 'button_apply'})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it be fixed?
const prepareDndItems = (tableColumnItems: TableColumnSetupItem[]) => { | ||
return tableColumnItems.map<Item>((tableColumnItem) => { | ||
const hasSelectionIcon = tableColumnItem.isRequired === false; | ||
const prepareStikyState = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const prepareStikyState = ( | |
const prepareStickyState = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,130 @@ | |||
import React from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we can't just move the component outside the Table?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is only to save backward compatibility with old TableColumnSetup
, TableColumnSetup
from Table
is not exportable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's simply move it up to the components. It should be the one component. Keep backward compatibility with old versions and add sticky feature
662224f
to
79d33de
Compare
@@ -0,0 +1,130 @@ | |||
import React from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's simply move it up to the components. It should be the one component. Keep backward compatibility with old versions and add sticky feature
No description provided.